package com.twu.biblioteca;

import java.util.ArrayList;
import java.util.List;

public class Library {
    private List<Book> books;
    private static Library instance;
    private static String LINE_SEPARATOR = System.getProperty("line.separator");

    static {
        instance = new Library();
    }

    private Library() {
        books = new ArrayList<Book>();
    }

    public static Library getInstance() {
        return instance;
    }

    public List<Book> getBooks() {
        return books;
    }

    public void addBook(Book book) {
        books.add(book);
    }

    public String getBookMessages() {
        StringBuilder message = new StringBuilder();
        for (int i = 0, size = books.size(); i < size; i++) {
            message.append("index: ").append(i + 1).append(LINE_SEPARATOR)
                    .append(books.get(i).getInfo()).append(LINE_SEPARATOR);
        }
        return message.toString();
    }
}
